package com.jse.util;

import java.util.HashMap;
import java.util.Map;

public class CaseMap<V> extends HashMap<java.lang.String,V> {

	private static final long serialVersionUID = 1L;
	private boolean upperCase;
	
	public CaseMap() {super();}
	
	public CaseMap(boolean upperCase) {super();this.upperCase=upperCase;}
	
	public CaseMap(Map<? extends String, ? extends V> m) {
		putAll(m);
	}

	@Override
	public V put(String key, V value) {
		return super.put(upperCase?key.toUpperCase():key.toLowerCase(), value);
	}

	@Override
	public void putAll(Map<? extends String, ? extends V> m) {
		m.forEach((k,v)->{
			put(k, v);
		});
	}

	@Override
	public V putIfAbsent(String key, V value) {
		return super.putIfAbsent(upperCase?key.toUpperCase():key.toLowerCase(), value);
	}

	@Override
	public boolean replace(String key, V oldValue, V newValue) {
		return super.replace(upperCase?key.toUpperCase():key.toLowerCase(), oldValue, newValue);
	}

	@Override
	public V replace(String key, V value) {
		return super.replace(upperCase?key.toUpperCase():key.toLowerCase(), value);
	}

	
}
